import { ArgumentsHost, BadRequestException, ExceptionFilter, Catch, Inject, RequestTimeoutException} from "@nestjs/common";
import {Response, Request} from 'express'
@Catch(BadRequestException, RequestTimeoutException)
export class CustomExceptionFilter implements ExceptionFilter{
   constructor(@Inject('SUFFIX') private readonly SUFFIX) {}
    catch(exception: any, host: ArgumentsHost) {
        console.log('SUFFIX', this.SUFFIX)
        const ctx = host.switchToHttp()
        const request = ctx.getRequest<Request>()
        const response = ctx.getResponse<Response>()
        const status = exception.getStatus()
        response.status(status).json({
            statusCode: status,
            message: exception.getResponse()?.message?exception.getResponse()?.message: exception.getResponse(),
            timestamp: new Date().toLocaleString(),
            path: request.originalUrl,
            method: request.method
        })
    }
    
}